package com.neulogistics.core.customercenter.api.application.integrationevent.handler;

import com.blackto.lib.eventbus.abstraction.IIntegrationEventHandler;
import com.neulogistics.core.customercenter.api.application.integrationevent.subscribe.ReceiptIntegrationEvent;
import com.neulogistics.core.customercenter.api.application.integrationevent.subscribe.TransferInboundIntegrationEvent;
import com.neulogistics.core.customercenter.domain.model.aggregate.Order;
import com.neulogistics.core.customercenter.domain.model.enumeration.OrderStatus;
import com.neulogistics.core.customercenter.domain.repository.IOrderRepository;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.concurrent.CompletableFuture;

@Component
public class ReceiptIntegrationEventHandler implements IIntegrationEventHandler<ReceiptIntegrationEvent> {
    @Resource
    IOrderRepository orderRepository;

    @Override
    public CompletableFuture<Void> handle(ReceiptIntegrationEvent event) {
        // 查询订单，修改状态
        Order order = orderRepository.findById(event.orderId);
        order.setOrderStatus(OrderStatus.Completed);
        orderRepository.save(order);

        return CompletableFuture.completedFuture(null);
    }
}
